package com.qq.BFMRSE.extractWord;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import com.qq.BFMRSE.entity.tfWordInfo;




public class SelectHelper {
	public static List<tfWordInfo>getPouWordInfos(List<tfWordInfo>wordList,int count)
	{
		List<tfWordInfo>resultList=new ArrayList<tfWordInfo>();
		for(int i=1;i<wordList.size();i++)
		{
			tfWordInfo temInfo=wordList.get(i);
			double temptf_idf=temInfo.getTf()*temInfo.getIdf();
			int j=i-1;
			while(j>=0&&(temptf_idf>=(wordList.get(j).getIdf()*wordList.get(j).getTf()))){
			//while(j>=0&&temInfo.getTf()>=wordList.get(j).getTf()){
				wordList.set(j+1, wordList.get(j));
				j=j-1;
			}
			wordList.set(j+1, temInfo);
		}
		for(int i=0;i<count;i++)
		{
			resultList.add(wordList.get(i));
		}
		return resultList;
	}
	public static boolean isContainDigit(String word)
	{
		if(word.contains("0")||word.contains("1")||word.contains("2")||word.contains("3")||word.contains("4")
				||word.contains("5")||word.contains("6")||word.contains("7")||word.contains("8")||word.contains("9"))
			return true;
		else {
			return false;
		}
	}
	public static String getReFileName(String fileName)
	{
		int lastIndex=-1;
		int length=fileName.length();
		if(fileName.contains("\\"))
		{
			lastIndex=fileName.lastIndexOf("\\");
		}
		else if(fileName.contains("/"))
		{
			lastIndex=fileName.lastIndexOf('/');
		}
		return fileName.substring(lastIndex+1, length);
		
	}
	public static String getText(String fileName)
	{
		StringBuilder sb=new StringBuilder();
		try {
			BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
			String line="";
			while((line=br.readLine())!=null)
			{
				sb.append(line);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sb.toString();
	}
	
}
